package org.zero.orika.converter;

import ma.glasnost.orika.MappingContext;
import ma.glasnost.orika.converter.BidirectionalConverter;
import ma.glasnost.orika.metadata.Type;

/**
 * @author Zero (cnzeropro@qq.com)
 * @date 2021/9/1 16:14
 */
public class ByteAndBoolConverter extends BidirectionalConverter<Byte, Boolean> {

    @Override
    public Boolean convertTo(Byte source, Type<Boolean> destinationType, MappingContext mappingContext) {
        return source.compareTo((byte) 1) == 0;
    }

    @Override
    public Byte convertFrom(Boolean source, Type<Byte> destinationType, MappingContext mappingContext) {
        return source ? (byte) 1 : (byte) 0;
    }
}
